<?php

/**
 * This is the model class for table "comment".
 *
 * The followings are the available columns in table 'comment':
 * @property string $id
 * @property string $aid
 * @property string $uid
 * @property string $admin_id
 * @property string $reply_to
 * @property string $nickname
 * @property string $email
 * @property string $website_url
 * @property string $content
 * @property string $ip
 * @property integer $status
 * @property string $created_at
 * @property string $updated_at
 */
class Comment extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{comment}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('content, created_at', 'required'),
			array('status', 'numerical', 'integerOnly'=>true),
			array('aid, uid, admin_id, reply_to, created_at, updated_at', 'length', 'max'=>11),
			array('nickname, email, website_url, content, ip', 'length', 'max'=>255),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, aid, uid, admin_id, reply_to, nickname, email, website_url, content, ip, status, created_at, updated_at', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		    'article' => array(self::BELONGS_TO, 'Article', 'aid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '自增id',
			'aid' => '文章id',
			'uid' => '用户id,游客为0',
			'admin_id' => '管理员id,其他人员对其回复为0',
			'reply_to' => '回复的评论id',
			'nickname' => '昵称',
			'email' => '邮箱',
			'website_url' => '个人网址',
			'content' => '回复内容',
			'ip' => '回复ip',
			'status' => '状态,0.未审核,1.已通过',
			'created_at' => '创建时间',
			'updated_at' => '最后修改时间',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('aid',$this->aid,true);
		$criteria->compare('uid',$this->uid,true);
		$criteria->compare('admin_id',$this->admin_id,true);
		$criteria->compare('reply_to',$this->reply_to,true);
		$criteria->compare('nickname',$this->nickname,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('website_url',$this->website_url,true);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('ip',$this->ip,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('created_at',$this->created_at,true);
		$criteria->compare('updated_at',$this->updated_at,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Comment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
